package com.explorer.ider.bootguide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.explorer.ider.bootguide.R;
import com.explorer.ider.bootguide.utils.TimeZoneUtils;

/**
 * Created by Eric on 2016/9/9.
 */
public class MyTimeZoneListAdapter extends BaseAdapter{

    Context mContext;
    private LayoutInflater inflate;
    private String[][] myTimeZones;
    private int mtTimeListLength;
    TimeZoneUtils myTimeZoneUtils;

    public MyTimeZoneListAdapter(Context context,String[][] myTimeZones,TimeZoneUtils timeZoneUtils){
        this.mContext = context;
        this.myTimeZones = myTimeZones;
        myTimeZoneUtils = timeZoneUtils;
        mtTimeListLength = myTimeZones.length;
        inflate = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mtTimeListLength;
    }

    @Override
    public Object getItem(int i) {
        return myTimeZoneUtils.getTimeZoneName(myTimeZones[i][1]);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = inflate.inflate(R.layout.time_zone_list_adapter_item,null);
            holder = new ViewHolder();
            holder.timeArea = (TextView) view.findViewById(R.id.id_time_zoom_list_item_area);
            holder.timeLag = (TextView) view.findViewById(R.id.id_time_zoom_list_item_lag);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }

            holder.timeArea.setText(myTimeZoneUtils.getTimeZoneName(myTimeZones[i][1]));
            holder.timeLag.setText(myTimeZones[i][0]);


        return view;

    }

    public class ViewHolder{
        public TextView timeArea;
        public TextView timeLag;
    }

}
